package vip.xiaonuo.smzq.modular.kcl.controller;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.smzq.modular.kcl.entity.Sjgl;
import vip.xiaonuo.smzq.modular.kcl.service.ISjglService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import vip.xiaonuo.common.pojo.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.File;


/**
 * 数据管理mdb导入
 *
 * @author sqq
 * @since 2024-03-25
 */
@Api(tags = "数据管理mdb导入")
@RestController
@RequestMapping("/kcl/sjgl")
@Validated
public class SjglController {

    @Resource
    private ISjglService iSjglService;

    /**
     * 添加数据管理mdb导入
     */
    @ApiOperation("添加数据管理mdb导入")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid Sjgl sjgl) {
        iSjglService.save(sjgl);
        return CommonResult.ok();
    }

    /**
     * 删除数据管理mdb导入
     */
    @ApiOperation("删除数据管理mdb导入")
    @PostMapping("/delete")
    public CommonResult<String> delete(@ApiParam(name = "pkid", value = "主键") @RequestParam String pkid) {
        iSjglService.removeById(pkid);
        return CommonResult.ok();
    }

    /**
     * 根据年度删除所有数据
     */
    @ApiOperation("根据年度删除所有数据")
    @PostMapping("/deleteAll")
    public CommonResult<String> deleteList(@ApiParam(name = "pkid", value = "主键") @RequestBody @Valid Sjgl sjgl) {

        return CommonResult.data(iSjglService.deleteList(sjgl.getPkid()));
    }

    /**
     * 编辑数据管理mdb导入
     */
    @ApiOperation("编辑数据管理mdb导入")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid Sjgl sjgl) {
        iSjglService.updateById(sjgl);
        return CommonResult.ok();
    }

    /**
     * 判断当前年度是否存在相关数据
     */
    @ApiOperation("判断当前年度是否存在相关数据")
    @PostMapping("/getIfExistence")
    public CommonResult<Boolean> getIfExistence(@RequestBody @Valid Sjgl sjgl) {
        return CommonResult.data(iSjglService.getIfExistence(sjgl));
    }

    /**
     * 数据管理mdb导入分页查询
     */
    @ApiOperation("数据管理mdb导入分页查询")
    @GetMapping("/list")
    public CommonResult<Page<Sjgl>> page(Sjgl sjgl) {
        return CommonResult.data(iSjglService.page(sjgl));
    }

    /**
     * mdb文件导入
     */
    @ApiOperation("mdb文件导入")
    @PostMapping("/fileUploadMdb")
    public CommonResult<Boolean> fileUploadMdb(
            @RequestPart("file") MultipartFile file,
            @Validated Sjgl sjgl
    ) {
        return CommonResult.data(iSjglService.fileUploadMdb(file, sjgl));
    }

    /**
     * mdb文件导入强制导入
     */
    @ApiOperation("mdb文件导入强制导入")
    @PostMapping("/fileUploadMdbMandatory")
    public CommonResult<String> fileUploadMdb2(
            @RequestPart("file") MultipartFile file,
            @Validated Sjgl sjgl
    ) {
        return CommonResult.data(iSjglService.fileUploadMdb2(file, sjgl));
    }

    /**
     * mdb文件导出
     */
    @ApiOperation("mdb文件导出")
    @GetMapping("/fileExport")
    public CommonResult<String> fileExport(
            @ApiParam(name = "nd", value = "年度", required = true) @RequestParam Integer nd,
            @ApiParam(name = "sjlb", value = "数据类别（1.矿产地储备，2.压矿储备，3.评审备案，4.储量数据）", required = true) @RequestParam Integer sjlb,
            HttpServletResponse response
            ) {
        iSjglService.fileExport(nd,sjlb,response);
        return CommonResult.ok();
    }

}
